package com.huike.web.controller.review;


import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.review.pojo.Review;
import com.huike.review.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 该Controller主要是为了复习三层架构以及Mybatis使用的，该部分接口已经放开权限，可以直接访问
 * 同学们在此处编写接口通过浏览器访问看是否能完成最简单的增删改查
 */
@RestController
@RequestMapping("/review")
public class MybatisReviewController extends BaseController {

    @Autowired
    private ReviewService reviewService;
    //查询单个对象
    @GetMapping("/getById")
    public AjaxResult getById(Long id){
        Review review=reviewService.getById(id);
        return AjaxResult.success(review);
    }
    //分页查询多个对象
    @GetMapping("/getDataByPage")
    public TableDataInfo getByPage(){
        List<Review> list=reviewService.getByPage();
        return getDataTable(list);
    }
    //新增员工
    @GetMapping("/saveData/{name}/{age}/{sex}")
    public AjaxResult saveDate(@PathVariable(value = "name")String name,@PathVariable("age")Integer age
            ,@PathVariable("sex") String sex){
        reviewService.saveDate(name,age,sex);
        return AjaxResult.success();
    }
    @PostMapping("/saveData")
    public AjaxResult save(@RequestBody Review review){
        reviewService.save(review);
        return AjaxResult.success();

    }
    //根据id修改
    @PutMapping("/update")
    public AjaxResult updateById(@RequestBody Review review){
        reviewService.updateById(review);
        return AjaxResult.success();

    }
    @DeleteMapping("/remove/{id}")
    public AjaxResult deleteById(@PathVariable("id") Long id){
        reviewService.deleteById(id);
        return AjaxResult.success();
    }
}